<?php
session_start();
include 'logic/Connection.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN" dir="ltr">
    <head profile="http://gmpg.org/xfn/11">
        <title>Search PhoneMall</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <meta http-equiv="imagetoolbar" content="no" />
        <link rel="stylesheet" href="styles/layout.css" type="text/css" />
        <script type="text/javascript" src="scripts/mootools.js"></script>
        <script type="text/javascript" src="scripts/events.js"></script>
    </head>
    <body id="top">
        <div id="xcontainer">
            <div class="wrapper col1">
                <div class="accordion">
                    <div id="socialise">
                        <ul>
                            <li><a href="#"><img src="images/linkedin.gif" alt="" /><span>Linked In</span></a></li>
                            <li><a href="#"><img src="images/skype.gif" alt="" /><span>Skype</span></a></li>
                            <li><a href="#"><img src="images/facebook.gif" alt="" /><span>Facebook</span></a></li>
                            <li><a href="#"><img src="images/rss.gif" alt="" /><span>FeedBurner</span></a></li>
                            <li class="last"><a href="#"><img src="images/twitter.gif" alt="" /><span>Twitter</span></a></li>
                        </ul>
                        <br class="clear" />
                    </div>
                </div>
            </div>
            <div class="wrapper col2">
                <div id="header">
                    <p class="toggler"><a href="#socialise">Open &amp; Close SocialBar</a></p>
                    <div id="logo">
                        <img src="images/logo.JPG" alt="logo" width="260px" height="140px"/>
                    </div>
                    <br class="clear" />
                </div>
            </div>
            <!-- ####################################################################################################### -->
            <div id="menu">
                <ul id="topnav">
                    <li><a href="index.php">Home</a></li>
                    <li>
                        <a href="products.php">Products</a>
                        <!--Subnav Starts Here-->
                        <span>
                            <a href="searchPage.php?prod='nokia'">Nokia</a> |
                            <a href="searchPage.php?prod='sony'">Sony Ericsson</a> |
                            <a href="searchPage.php?prod='sam'">Samsung</a> |
                            <a href="searchPage.php?prod='phil'">Philips</a> |
                            <a href="searchPage.php?prod='apple'">Apple</a> |
                            <a href="searchPage.php?prod='lg'">LG</a>
                        </span>
                        <!--Subnav Ends Here-->
                    </li>
                    <li>
                        <a href="#">Services</a>
                        <span>
                            <a href="#">Send Gifts</a> |
                            <a href="#">Newsletter</a> |
                            <a href="#">Our Work</a>
                        </span>
                    </li>
                    <li><a href="#">Contact Us</a></li>
                    <li>
                        <a href="#">About</a>
                        <span>
                            <a href="#">Phone Mall</a> |
                            <a href="#">Team</a> |
                            <a href="#">Jobs</a>
                        </span>
                    </li>
                </ul>
            </div>
            <!-- ####################################################################################################### -->
            <div class="wrapper col3">
                <div id="breadcrumb">
                    <ul>
                        <li class="first">You Are Here</li>
                        <li>&#187;</li>
                        <li><a href="#">Home</a></li>
                        <li>&#187;</li>
                        <li><a href="#">Grand Parent</a></li>
                        <li>&#187;</li>
                        <li><a href="#">Parent</a></li>
                        <li>&#187;</li>
                        <li class="current"><a href="#">Child</a></li>
                    </ul>
                </div>
            </div>
            <!-- ####################################################################################################### -->
            <div class="wrapper col4">
                <div id="container">
                    <div id="content">
                        <?php
                        if (!(isset($_REQUEST['pagenum']))) {
                            $pagenum = 1;
                        }
                        else {
                            $pagenum  = $_REQUEST['pagenum'];
                        }

                        if(isset ($_REQUEST['product']) && $_REQUEST['product'] != 'none') {
                            $fltProduct = $_REQUEST['product'];
                        }
                        else {
                            $fltProduct = "%";
                        }

                        if (isset ($_REQUEST['feature']) && $_REQUEST['feature']!='none') {
                            $fltFeature = $_REQUEST['feature'];
                        }
                        else {
                            $fltFeature  = "%";
                        }

                        if(isset ($_REQUEST['price']) && $_REQUEST['price']!='none') {
                            list ($upper, $lower) = split(':', $_REQUEST['price']);
                            echo $upper . " " . $lower;
                        }
                        else {
                            $upper = 100000;
                            $lower = 0;
                        }

                        $dbClass = new Connection();
                        $defaultQuery = "SELECT * FROM mp_tb_product WHERE MP_PRD_BRAND LIKE '" . $fltProduct . "' AND MP_PRD_FEATURE LIKE '".
                                $fltFeature . "' AND MP_PRD_PRICE BETWEEN " .$lower. " AND " .$upper. " ORDER BY MP_PRD_ID ";

                        if(isset ($_SESSION['sqlQuery'])) {
                            if($_SESSION['sqlQuery']!=$defaultQuery) {
                                $_SESSION['sqlQuery'] = $defaultQuery;
                                $_SESSION['$Filered'] = TRUE;
                            }
                            else {
                                $_SESSION['$Filered'] = FALSE;
                            }
                        }
                        else {
                            $_SESSION['sqlQuery'] = $defaultQuery;
                            $_SESSION['$Filered'] = FALSE;
                        }
                        //count the number of results Edit $data to be your query
                        $data = $dbClass->query($defaultQuery);
                        $rows = mysql_num_rows($data);

                        //This is the number of results displayed per page
                        $page_rows = 4;
                        //This tells us the page number of our last page
                        $last = ceil($rows/$page_rows);

                        //this makes sure the page number isn't below one, or more than our maximum pages
                        if ($pagenum < 1) {
                            $pagenum = 1;
                        }
                        elseif ($pagenum > $last) {
                            $pagenum = $last;
                        }

                        //sets the range to display in query

                        if($_SESSION['$Filered'])
                            $pagenum = 1;

                        $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

                        $sql_page = "SELECT * FROM mp_tb_product WHERE MP_PRD_BRAND LIKE '" . $fltProduct . "' AND MP_PRD_FEATURE LIKE '".
                                $fltFeature . "' AND MP_PRD_PRICE BETWEEN " .$lower. " AND " .$upper. " ORDER BY MP_PRD_ID ". $max;

                        $data_page = $dbClass->query($sql_page);
                        //This is where you display your query results
                        $content = "<table class=\"browseTable\" cellpadding=\"0\" cellspacing=\"0\">";
                        while($row = mysql_fetch_array( $data_page )) {
                            $content .= "<tr><td><div class=\"tableDiv\"><center><img align=\"middle\" src=\"images/products/".$row['MP_PRD_IMAGE']."\" width=\"180px\" height=\"240px\" alt=\"\"/><br/>"
                                    . "<p>".$row['MP_PRD_BRAND']. " " .$row['MP_PRD_MODEL'] . "</p>"
                                    . "<p sytle=\"font-size: xx-small;\">".$row['MP_PRD_DESCRIPTION']."</p>"
                                    ."<a href=\"CartPage.php?action=add&id=". $row['MP_PRD_ID'] ."\"><input class=\"btn\" type =\"button\" value=\"Add to Cart\" name=\"btnCart\" /></a>&nbsp;"
                                    . "<a href=\"products.php?pid=".$row['MP_PRD_ID']."\" ><input class=\"btn\" type =\"button\" value=\"Read More\"/></a>"
                                    . "</center> </div></td></tr>";
                            echo $row['MP_PRD_IMAGE'];
                        }
                        $content .= "</table>";

                        echo "myfucking : " . $content;
                        echo '<p>';

// This shows the user what page they are on, and the total number of pages
                        echo " --Page $pagenum of $last-- <p>";
                        echo $sql_page;
                        ?>
                        <div id="searchTable">


                        </div>
                        <div id="pageDiv">
                            <?php
                            echo $_SERVER['REQUEST_URI'];
                            if ($pagenum == 1) {
                            }
                            else {
                                if(strpos($_SERVER['REQUEST_URI'], 'fea') !== false) {
                                    echo " <a href='{$_SERVER['REQUEST_URI']}&pagenum=1'> <<-First</a> ";
                                }
                                else {
                                    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
                                }

                                echo " " ;
                                $previous = $pagenum-1;
                                if(strpos($_SERVER['REQUEST_URI'], 'fea') !== false) {
                                    echo " <a href='{$_SERVER['REQUEST_URI']}&pagenum=$previous'> <-Previous</a> ";
                                }
                                else {
                                    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
                                }
                            }

                            //just a spacer
                            echo " ---- ";

                            //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
                            if ($pagenum == $last) {
                            }
                            else {
                                $next = $pagenum+1;
                                if(strpos($_SERVER['REQUEST_URI'], 'fea') !== false) {
                                    echo " <a href='{$_SERVER['REQUEST_URI']}&pagenum=$next'>Next -></a>";
                                }
                                else {
                                    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a>";
                                }
                                echo " ";
                                if(strpos($_SERVER['REQUEST_URI'], 'fea') !== false) {
                                    echo " <a href='{$_SERVER['REQUEST_URI']}&pagenum=$last'>Last ->></a> ";
                                }
                                else {
                                    echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
                                }
                            }


                            ?>
                        </div>
                        <br class="clear" />

                    </div>
                    <div id="column">
                        <div class="subnav">
                            <h2>Filter</h2>
                            <form name="f1" id="f1" action="" method="post">
                                <ul class="filterBar">
                                    <li>Product<br />
                                        <select id="product" name="product" class="select" onchange="submit();">
                                            <option class="option" selected="true" value="none">Select</option>
                                            <option class="option" value="nokia">Nokia</option>
                                            <option class="option" value="sony">Sony Ericsson</option>
                                            <option class="option" value="samsung">Samsung</option>
                                            <option class="option" value="other">Other</option>
                                        </select>
                                    </li>
                                    <li>Price<br />
                                        <select id="price" name="price" class="select" onchange="submit();">
                                            <option class="option" selected="true" value="none">Select</option>
                                            <option class="option" value="5000:1000">Rs 1000 - 5000</option>
                                            <option class="option" value="10000:5001">Rs 5000 - 10000</option>
                                            <option class="option" value="20000:10001">Rs 10000 - 20000</option>
                                            <option class="option" value="30000:20001">Rs 20000 - 30000</option>
                                            <option class="option" value="50000:30001">Rs 30000 - 50000 </option>
                                            <option class="option" value="100000:50001">Rs 50000+ </option>
                                        </select>
                                    </li>
                                    <li>Features <br />
                                        <select id="technology" name="feature" class="select" onchange="submit();">
                                            <option class="option" selected="true" value="none">Select</option>
                                            <option class="option" value="smart">Smart Phone</option>
                                            <option class="option" value="3G">3G Phone</option>
                                            <option class="option" value="Music">Music Phone</option>
                                            <option class="option" value="Camera">Camera Phone</option>
                                            <option class="option" value="Radio">Radio Phone</option>
                                        </select>
                                    </li>
                                    <li><input type="button" value="Filter" class="btn" onclick=""/></li>
                                </ul>
                            </form>
                        </div>
                        <div id="featured">
                            <ul>
                                <li>
                                    <h2>Featured</h2>
                                    <p class="imgholder"><img src="images/products/apple_phone.jpg" width="180px" height="250px" alt="" /></p>
                                    <p>3-MP Camera, Voice Control, Compass, Cut, Copy & Paste, Landscape Keyboard, Internet Tethering plus Everything you love about iPhone.</p>
                                    <p class="readmore"><a href="#">Read More &raquo;</a></p>
                                </li>
                            </ul>
                        </div>

                    </div>
                    <div class="clear"></div>
                </div>
            </div>
            <!-- ####################################################################################################### -->
            <div class="wrapper col5">
                <div id="footer">
                    <div class="box1">
                        <h2>PhoneMall (Pvt) Ltd.</h2>
                        <img class="imgl" src="images/apple_partner.jpg" alt="" height="70" width="120"/>
                        <img class="imgl" src="images/nokia_partner.jpg" alt="" height="70" width="120"/>
                        <p>PhoneMall is registered trade marks of PhoneMall (pvt) Ltd. <br/>We are currently acting as the dealers of Apple &amp;
                            Nokia in south asian region providing the same quality of the mother companies.</p>
                        <p>We provide you with the outstanding service, and we certify your delivery withing 4 weeks or your money back.</p>
                    </div>
                    <div class="box contactdetails">
                        <h2><br/>Contact PhoneMall</h2>
                        <ul>
                            <li>PhoneMall (pvt) Ltd</li>
                            <li>No 71, Kottawa Road,</li>
                            <li>Rajagiriya</li>
                            <li></li>
                            <li>Tel: 0094 112880000</li>
                            <li>Fax: 0094 112880004</li>
                            <li>Email: info@phonemall.com</li>
                            <li class="last">LinkedIn: <a href="http://lk.linkedin.com/in/hashanj">PhoneMall</a></li>
                        </ul>
                    </div>
                    <br class="clear" />
                </div>
            </div>
            <!-- ####################################################################################################### -->
            <div style="clear: both"></div>
        </div>
        <!-- ####################################################################################################### -->
        <script type="text/javascript" src="scripts/toggle.js"></script>
    </body>
</html>
